#include "Box.h"

Box::Box(b2World* world, b2Vec2 boxPosition, float32 boxSize, float32 boxDensity, float32 boxFriction)
{
	m_world = world;
	m_boxPosition = boxPosition;
	m_boxSize = boxSize;
	m_boxDensity = boxDensity;
	m_boxFriction = boxFriction;
	m_isTouched = false;

	b2BodyDef myBodyDef;
	myBodyDef.type = b2_dynamicBody;
	myBodyDef.position = m_boxPosition;
	myBodyDef.userData = &m_isTouched;

	b2PolygonShape polygonShape;
	polygonShape.SetAsBox(m_boxSize, m_boxSize);

	b2FixtureDef myFixtureDef;
	myFixtureDef.shape = &polygonShape;
	myFixtureDef.density = m_boxDensity;
	myFixtureDef.friction = m_boxFriction;

	m_boxBody = m_world -> CreateBody(&myBodyDef);
	m_boxBody -> CreateFixture(&myFixtureDef);
}

Box::~Box()
{
	if(m_boxBody != NULL)
	{
		m_world ->DestroyBody(m_boxBody);
		m_boxBody = NULL;
	}
}

b2Vec2 Box::GetBoxPosition()
{
	return m_boxBody->GetPosition();
}

b2Body* Box::GetBoxBody()
{
	return m_boxBody;
}

float32 Box::GetBoxFriction()
{
	return m_boxFriction;
}

void Box::SetBoxFriction(const float32& val)
{
	m_boxFriction = val;
}

float32 Box::GetBoxDensity()
{
	return m_boxDensity;
}

void Box::SetBoxDensity(const float32& val)
{
	m_boxDensity = val;
}

float32 Box::GetBoxSize()
{
	return m_boxSize;
}

void Box::SetBoxSize(const float32& val)
{
	m_boxSize = val;
}

bool Box::IsBoxTouched()
{
	return m_isTouched;
}

void Box::SetBoxTouched(const bool& val)
{
	m_isTouched = val;
}